﻿using System.Collections.Generic;
using Newtonsoft.Json;

namespace Hourglass.Qrobot.Models
{
    public sealed class PollResponse : BaseResponse<List<PollMessage>>
    {
        /// <summary>
        /// 错误信息
        /// </summary>
        [JsonProperty("errmsg")]
        public string ErrorMessage { get; set; }

        /// <summary>
        /// 被迫下线说明
        /// </summary>
        [JsonProperty("t")]
        public string OfflineMark { get; set; }

        /// <summary>
        /// 需要替换的ptwebqq
        /// </summary>
        [JsonProperty("p")]
        public string Ptwebqq { get; set; }
    }

    public sealed class PollMessage
    {
        /// <summary>
        /// 消息类型[discu_message/group_message/message/kick_message]
        /// </summary>
        [JsonProperty("poll_type")]
        public string PollType { get; set; }

        /// <summary>
        /// 消息体
        /// </summary>
        [JsonProperty("value")]
        public MessageValue Value { get; set; }

        #region Internal Class

        public sealed class MessageValue
        {
            /// <summary>
            /// 第一项是一个数组，数组包含两项，第一项固定font字符串，第二项为对象，格式： {"color": "000000", "name": "微软雅黑", "size": 10, "style": [0, 0, 0]}
            /// 后面的项为消息内容，注意在有@人的内容时，会将消息分割为多项，否则只有一项。并且注意，@人这一项内容后会存在空字符串项，然后再是内容项
            /// 实例：[["font",{"color":"000000","name":"微软雅黑","size":10,"style":[0,0,0]}],"@you",""," 在不在啊"]
            /// </summary>
            [JsonProperty("content")]
            public List<object> Content { get; set; }

            /// <summary>
            /// 发送方：QQ群组Code/讨论组ID/个人ID（单人聊天）
            /// </summary>
            [JsonProperty("from_uin")]
            public long FromUin { get; set; }

            /// <summary>
            /// QQ群组Code
            /// </summary>
            [JsonProperty("group_code")]
            public long GroupCode { get; set; }

            /// <summary>
            /// 讨论组ID
            /// </summary>
            [JsonProperty("did")]
            public long DisscussId { get; set; }

            [JsonProperty("msg_id")]
            public long MessageId { get; set; }

            /// <summary>
            /// 作用未知，群消息、讨论组消息、个人消息都是0
            /// </summary>
            [JsonProperty("msg_type")]
            public int MessageType { get; set; }

            /// <summary>
            /// 发送人ID（如果是单人聊天，该字段无值）
            /// </summary>
            [JsonProperty("send_uin")]
            public long SendUin { get; set; }

            /// <summary>
            /// 接收人ID
            /// </summary>
            [JsonProperty("to_uin")]
            public long ToUin { get; set; }

            /// <summary>
            /// 1970.1.1至今的秒数
            /// </summary>
            [JsonProperty("time")]
            public long Time { get; set; }
        }

        #endregion Internal Class
    }
}
